package com.redoor.app.stake.basicdata.controller;

import com.redoor.app.stake.basicdata.commons.BasicDataStatus;
import com.redoor.app.stake.basicdata.model.BaseConsts;
import com.redoor.app.stake.basicdata.service.BaseConstsService;
import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Created by wangjunlei on 2018-03-04 14:13:22.
*/
@RestController
@RequestMapping("/base/constss")
public class BaseConstsController {

    @Autowired
    private BaseConstsService baseConstsService;

    @GetMapping("/initConstsToRedis")
    public ResponseResult initConstsToRedis() {
        baseConstsService.initConstsToRedis();
        return ResultGenerator.generatorSuccess();
    }

    @GetMapping("/{id}")
    public ResponseResult detail(@PathVariable String id) {
        BaseConsts baseConsts = baseConstsService.findById(id);
        return ResultGenerator.generatorSuccess(baseConsts);
    }

    @ApiOperation(value = "根据code获取常量列表", notes = "")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "code", value = "常量的code", paramType = "query", dataType = "String", required = true, defaultValue = "")
    })
    @GetMapping("/list")
    public ResponseResult list(String code) {
        if(StringUtils.isEmpty(code)){
            return ResultGenerator.generatorFail(BasicDataStatus.CONSTSCODE_NOT_EXISTS);
        }
        List<BaseConsts> baseConsts = baseConstsService.getConstsList(code);
        return ResultGenerator.generatorSuccess(baseConsts);
    }


    @ApiOperation(value = "获取充电站类型列表", notes = "")
    @GetMapping("/stationTypeSelectList")
    public ResponseResult list() {
        List<BaseConsts> baseConsts = baseConstsService.getConstsList("30041224");
        return ResultGenerator.generatorSuccess(baseConsts);
    }
}
